<template>
  <div class="goods-list">
    <div class="goods-item" @click="goDetail(item.id)" v-for="item in goodlist" :key="item.id">
      <img :src="item.img_url" alt />
      <h1 class="title">{{item.title}}</h1>
      <div class="info">
        <p class="price">
          <span class="now">{{item.sell_price}}</span>
          <span class="old">{{item.market_price}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩{{item.stock_quantity}}件</span>
        </p>
      </div>
    </div>
 
 <mt-button type="danger" size="large" @click="goodlistmore">加载更多</mt-button>
 
  </div>
</template>
<script>
export default {
  data() {
    return {
      pageindex: 1,
      goodlist: []
    };
  },
  created() {
    this.goodlists();
  },
  methods: {
    goodlists() {
      // 获取商品列表
      this.$http
        .get("api/getgoods?pageindex=1")
        .then(result => {
          if (result.body.status === 0) {
            this.goodlist = this.goodlist.concat(result.body.message);
          } else {
            console.log(89);
          }
        });
    },
    goodlistmore(){
        this.pageindex++;
        this.goodlists();
    },
    goDetail(id){
      // 使用js的形式进行路由导航
      // 注意：一定要区分this.$route和this.$router这两个对象
      // 其中：this.$route是路由参数对象，多有路由中的参数params query都属于他
      // this.$router  是一个路由导航对象，实现路由的前进后退ur地址
      // this.$router.push("/home/goodlistinfo/"+id);
      //  this.$router.push({path:"/home/goodlistinfo/"+id});
      this.$router.push({name:"goodlistinfo",params:{id}})

    }
  }
};
</script>
<style lang="less" scoped>
.goods-list {
  padding: 10px;
  justify-content: space-between;
  display: flex;
  flex-wrap: wrap;
  .goods-item {
    width: 49%;
    border: 1px solid #eee;
    box-shadow: 0 0 8px #eee;
    margin: 3px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 300px;

    img {
      width: 100%;
      min-height:200px;
    }
    h1 {
      font-size: 16px;
    }
    .info {
      background: #eee;
      padding: 4px 6px;
      p {
        margin: 0;
      }
      .price {
        .now {
          color: chocolate;
        }
        .old {
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 10px;
        }
      }
      .sell {
        justify-content: space-between;
        display: flex;
      }
    }
  }
}
</style>


